

package com.ourteam.education.dao.impl ;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.beanutils.PropertyUtils;

import org.springframework.jdbc.core.RowMapper;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;


import com.ourteam.education.dao.CourseDefine;
import com.ourteam.education.dao.CourseDefineDAOQueryBean;
import com.ourteam.education.dao.ICourseDefineDAO;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2019-09-22 15:15:10
  * Warning ! This file will be overwrite when regenerate !
  * 
 */

public class AbstractCourseDefineDAOJdbcImpl 
    extends AbstractSpringDAO implements ICourseDefineDAO{
    
            
    	
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
						
			
			
				
		
	    
    					
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
    public static final String[] ENTITY_FIELDS = new String[] { Id,CourseTypeId,CourseName,SchoolYear,TeachingMode,ChargingMode,Status,Remarks,DeleteFlag,CourseTypeName };
	
	public static final String[] ENTITY_PROPERTIES = new String[] {_DataObjectProperty.Id,_DataObjectProperty.CourseTypeId,_DataObjectProperty.CourseName,_DataObjectProperty.SchoolYear,_DataObjectProperty.TeachingMode,_DataObjectProperty.ChargingMode,_DataObjectProperty.Status,_DataObjectProperty.Remarks,_DataObjectProperty.DeleteFlag,_DataObjectProperty.CourseTypeName};
	
	public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};
	
	private static String relatedJoinSQL = null;
	
	private static String basicFilterSQL = null;
	
	private DataAccessObjectHelper<CourseDefine, CourseDefineDAOQueryBean> daoHelper;
	
	public AbstractCourseDefineDAOJdbcImpl() {
		super();
		daoHelper = new DataAccessObjectHelper<CourseDefine, CourseDefineDAOQueryBean>(this);
	}
	
	protected String getEntityName() {
		return EntityName;
	}

	protected String[] getEntityFields() {
		return ENTITY_FIELDS;
	}

	protected String[] getEntityProperties() {
		return ENTITY_PROPERTIES;
	}

	protected String[] getEntityPKFields() {
		return ENTITY_PK_FIELDS;
	}
	
	protected String[] getEntityAutoGenPKFields(){
		return ENTITY_AUTO_GEN_PK_FIELDS;
	}
	
	
	protected String[] getEntityUniqueFields() {
		return ENTITY_UNIQUE_FIELDS;
	}
	
	protected String getBaiscQueryFilter(){
	
		if(basicFilterSQL == null){
                        StringBuffer basicFilterSQLbuffer = new StringBuffer();
						
			basicFilterSQLbuffer.append(DeleteFlag).append("=  0  ");
			
						
						
			basicFilterSQL = basicFilterSQLbuffer.toString();
		}
		
		return basicFilterSQL;
	}
	
	protected String getRelatedJoinSQL(){
		
		if(relatedJoinSQL == null){
			StringBuffer relatedJoinSQLBuffer = new StringBuffer();
			
						
			            
            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                .append(com.ourteam.education.dao.ICourseTypeDAO.EntityName)
                .append(" RELATED_HNV2TF_CourseType ");
			
			 relatedJoinSQLBuffer.append(" ON ( ");
								                				
				relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICourseTypeDAO.Id,com.ourteam.education.dao.ICourseTypeDAO.EntityName + ".","RELATED_HNV2TF_CourseType."));
				relatedJoinSQLBuffer.append(" = ").append(CourseTypeId);
					
								                
                                                
                                
                                
                    			
    			relatedJoinSQLBuffer.append(" AND ");  
    			
    			                
                relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICourseTypeDAO.DeleteFlag,com.ourteam.education.dao.ICourseTypeDAO.EntityName + ".", "RELATED_HNV2TF_CourseType.")).append(" ").append("=  0  ");
			
                			
			    			
			
            relatedJoinSQLBuffer.append(" ) ");
						
			relatedJoinSQL = relatedJoinSQLBuffer.toString();
		}
		
		return relatedJoinSQL;
	}
	
    /**
	 * Check Data Unique
	 * @param aCourseDefine
	 * @throws Exception
	 */
	public boolean checkIsUnique(CourseDefine aCourseDefine) throws Exception{
	
		if(aCourseDefine == null){
			return true;
		}
	
		List valueList = new ArrayList();

		List pkValueList = new ArrayList();
		
		                
				
	    		
		pkValueList.add(aCourseDefine.getId());
				
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
				
		return isUnique(valueList.toArray(new Object[valueList.size()]), pkValueList
				.toArray(new Object[pkValueList.size()]));
	
	}
	
	/**
	 * Insert Data
	 * @param aCourseDefine
	 * @throws Exception
	 */
	public void insert(CourseDefine aCourseDefine) throws Exception{
		
						
		PropertyUtils.setProperty(aCourseDefine,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("0",int.class));
				
				
		super.doInsert(aCourseDefine);

	}

    /**
	 * Batch Insert Datas
	 * @param aCourseDefine
	 * @throws Exception
	 */
	public void batchInsert(CourseDefine[] aCourseDefines) throws Exception{
		
		 super.doBatchInsert(aCourseDefines);
		
	}

    /**
	 * Delete Data
	 * @param  final long id	 *
	 * @throws Exception
	 */
	public void delete( final long id ) throws Exception{

				
		CourseDefine tempCourseDefine = findById( id);
		
						
		PropertyUtils.setProperty(tempCourseDefine,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempCourseDefine);
				
	}
	
	/**
	 * Delete Datas
	 * @param queryBean 
	 * @throws Exception
	 */
	public void delete(CourseDefineDAOQueryBean queryBean) throws Exception{
	
				
		CourseDefine tempCourseDefine = new CourseDefine();
		
				
				
	    PropertyUtils.setProperty(tempCourseDefine,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempCourseDefine,queryBean);
				
	}
	
	public void delete(CourseDefine aCourseDefine) throws Exception {
				
				
									
						
					
				
		delete(aCourseDefine.getId());
		
	}
	
	/**
	 * Update Data Selective
	 * @param aCourseDefine
	 * @throws Exception
	 */
	public void update(CourseDefine aCourseDefine) throws Exception{
		
						
											
				
				
		if(aCourseDefine.getId() == 0){
			throw new Exception("Can not update object data whith out primary key value");
		}
				
		super.doUpdate(aCourseDefine);
		
		CourseDefine tempObj = findById(aCourseDefine.getId());
		
		if(tempObj != null){
			PropertyUtils.copyProperties(aCourseDefine, tempObj);
		}
	}
	
	/**
	 * Batch Update Datas
	 * @param aCourseDefines[]
	 * @throws Exception
	 */
	public void batchUpdate(CourseDefine[] aCourseDefines) throws Exception{
		
		super.doBatchUpdate(aCourseDefines);

	}

    /**
	 * Update Data By Condictions
	 * @param aCourseDefine
	 * @param aValueCriteria 
	 * @param aTransaction
	 * @throws Exception
	 */
	public void update(CourseDefine aCourseDefine, CourseDefineDAOQueryBean aQueryBean) throws Exception{
		
				
		super.doUpdateByQuery(aCourseDefine, aQueryBean);
		
	}
	
	/**
	 * Update Data By Condictions
	 * @param aQueryBean
	 * @throws Exception
	 */
	public void update(CourseDefineDAOQueryBean aQueryBean) throws Exception {
		super.doUpdateByQuery(aQueryBean);
	}


    protected void checkNullValue(CourseDefine aCourseDefine) throws Exception{	
																																																	
		if(aCourseDefine.getCourseTypeName() == null){
			throw new Exception("The CourseDefine.courseTypeName value is not allow NULL");
		}
																
	}
	
	/**
	 * Get Data By ID
	 * @param  final long id	 * @return  ${businessObject.name}
	 * @throws Exception
	 */
	public CourseDefine findById( final long id) throws Exception{
		
		    	                
    	    	                		
		CourseDefineDAOQueryBean queryBean = new CourseDefineDAOQueryBean();
		
		CourseDefineDAOQueryBean.Criteria  criteria = queryBean.createCriteria();
	
		                

		criteria.andIdEqualTo(id);
        
        
		//queryBean.setDistinct(true);
		
		CourseDefine[] CourseDefines = query(queryBean);
		
		if(CourseDefines.length == 0){
			return null;
		}
		else{
			return CourseDefines[0];
		}
		
	}

    /**
	 * Query Data
	 * @param queryBean
	 * @return CourseDefine[]
	 * @throws Exception
	 */
	public CourseDefine[] query(CourseDefineDAOQueryBean queryBean) throws Exception{
				
		List result = super
				.doQuery(queryBean, new JdbcCourseDefineRowMapper());

		return (CourseDefine[]) result.toArray(new CourseDefine[result.size()]);
	}
	
	/**
	 * Query ${businessObject.name} Selective
	 * @param queryBean
	 * @return Map[]
	 * @model
	 * @throws Exception
	 */
	public Map<String,Object>[] querySelective(CourseDefineDAOQueryBean queryBean)  throws Exception{
		
		if(queryBean.getSelectProperties().isEmpty()){
			queryBean.addAllSelectProperties();
		}
		
		return super.doQuerySelective(queryBean);
		
	}
	
	/**
	 * Query Data Count
	 * @param queryBean
	 * @return int
	 * @throws Exception
	 */
	public int queryCount(CourseDefineDAOQueryBean queryBean) throws Exception{
		
		return super.doQueryCount(queryBean);
		
	}
	
	public void synchronize(CourseDefine[] aCourseDefines, CourseDefineDAOQueryBean queryBean)
			throws Exception {
		daoHelper.synchronize(aCourseDefines,queryBean);
		
	}

	public void synchronize(CourseDefine[] aCourseDefines,
			CourseDefineDAOQueryBean queryBean,
			net.dao.IDataAccessInterface.ISynchronizeCallback<CourseDefine> callBack)
			throws Exception {
		daoHelper.synchronize(aCourseDefines,queryBean,callBack);
	}

    
     public static class JdbcCourseDefineRowMapper implements
			RowMapper<CourseDefine> {

		public CourseDefine mapRow(ResultSet resultSet, int arg1) throws SQLException {
			CourseDefine object = new CourseDefine();

			int columnIndex = 1;
			
			int __dataType;
			
			try{
													
	            	            
				Object id = null;
				
								
				id =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdNull(resultSet.getBoolean(columnIndex++));
				
				if(id != null){
				
                    setBeanValue(object, _DataObjectProperty.Id,id);
				}
				
					
	            	            
				Object courseTypeId = null;
				
								
				courseTypeId =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseTypeIdNull(resultSet.getBoolean(columnIndex++));
				
				if(courseTypeId != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseTypeId,courseTypeId);
				}
				
					
	            	            
				Object courseName = null;
				
								
				courseName =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseNameNull(resultSet.getBoolean(columnIndex++));
				
				if(courseName != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseName,courseName);
				}
				
					
	            	            
				Object schoolYear = null;
				
								
				schoolYear =  resultSet.getObject(columnIndex++);
				
				               
				object.setSchoolYearNull(resultSet.getBoolean(columnIndex++));
				
				if(schoolYear != null){
				
                    setBeanValue(object, _DataObjectProperty.SchoolYear,schoolYear);
				}
				
					
	            	            
				Object teachingMode = null;
				
								
				teachingMode =  resultSet.getObject(columnIndex++);
				
				               
				object.setTeachingModeNull(resultSet.getBoolean(columnIndex++));
				
				if(teachingMode != null){
				
                    setBeanValue(object, _DataObjectProperty.TeachingMode,teachingMode);
				}
				
					
	            	            
				Object chargingMode = null;
				
								
				chargingMode =  resultSet.getObject(columnIndex++);
				
				               
				object.setChargingModeNull(resultSet.getBoolean(columnIndex++));
				
				if(chargingMode != null){
				
                    setBeanValue(object, _DataObjectProperty.ChargingMode,chargingMode);
				}
				
					
	            	            
				Object status = null;
				
								
				status =  resultSet.getObject(columnIndex++);
				
				               
				object.setStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(status != null){
				
                    setBeanValue(object, _DataObjectProperty.Status,status);
				}
				
					
	            	            
				Object remarks = null;
				
								
				remarks =  resultSet.getObject(columnIndex++);
				
				               
				object.setRemarksNull(resultSet.getBoolean(columnIndex++));
				
				if(remarks != null){
				
                    setBeanValue(object, _DataObjectProperty.Remarks,remarks);
				}
				
					
	            	            
				Object deleteFlag = null;
				
								
				deleteFlag =  resultSet.getObject(columnIndex++);
				
				               
				object.setDeleteFlagNull(resultSet.getBoolean(columnIndex++));
				
				if(deleteFlag != null){
				
                    setBeanValue(object, _DataObjectProperty.DeleteFlag,deleteFlag);
				}
				
								
				            	            	            					            	            	
	            	            
				Object courseTypeName = null;
				
								
				courseTypeName =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseTypeNameNull(resultSet.getBoolean(columnIndex++));
				
				if(courseTypeName != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseTypeName,courseTypeName);
				}
				
																
				return object;
			}catch(Exception e){
				throw new SQLException(e.getMessage());
			}
		}

	}
	
}